package com.test.task.controller;

import com.test.task.beans.User;
import com.test.task.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @DATE 2021/6/19 - 19:24
 */
@Controller
public class LoginController {


    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request, Model model){
        User login = loginService.login(user);
        if(login!=null){
            request.getSession().setAttribute("user", login);
        }else {
            model.addAttribute("loginErrorMsg", "账号或密码有误,请重新登录！");
            return "/index";
        }
        if(login.getFlag().equals("系统管理员")) {
            return "/admin/index";
        }else if(login.getFlag().equals("主管")){
            return "/manager/index";
        }else{
            return "/staff/index";
        }

    }
}
